<?php
/**
* 优惠券 
*/ 
namespace app\adm\model;
use think\Db;
class Coupons
{
    /**
    * 优惠券列表
    */
    public function couponsList()
    {
        
        $page=Db::name('coupons')->order('couponAddTime desc')->paginate(10);
        $couponsList['page']=$page;
        $couponsList['list']=$page->all();
        foreach ($couponsList['list'] as $key => $value) {
            $couponsList['list'][$key]['dates']=strtotime(date('Y-m-d'));
        }
        if($couponsList){
            return $couponsList;
        }else{
            return false;
        }
    }
    /**
    * 领取当前优惠券的所有用户
    */
    public function userCouponsList($couponId)
    {
        $where['couponId']=$couponId;
        $page=Db::name('CouponsUser')->where($where)->paginate(10);
        $userCouponsList['page']=$page;
        $userCouponsList['list']=$page->all();
        foreach ($userCouponsList['list'] as $key => $value) {
            $userid['userid']=$value['userid'];
            $user=Db::name('user')->where($userid)->find();
            $userCouponsList['list'][$key]['nickname']=$user['nickname'];
            $userCouponsList['list'][$key]['tel']=$user['tel'];
        }
        if($userCouponsList){
            return $userCouponsList;
        }else{
            return false;
        }
    }
    /**
    * 优惠券发布
    */
    public function couponup($couponId)
    {
        $where['couponId']=$couponId;
        $data['couponstart']=1;
        $couponup=Db::name('coupons')->where($where)->update($data);
        if($couponup){
            return true;
        }else{
            return false;
        }
    }
    /**
    * 优惠券删除
    */
    public function couponDel($couponId)
    {
        $where['couponId']=$couponId;
        $coupondel=Db::name('coupons')->where($where)->delete();
        if($coupondel){
            return true;
        }else{
            return false;
        }
    } 
}